package org.southyin.springboot02.commons;

/**
 * 通用响应类
 * @param <T>
 */
public class CommonsResp<T> {
    private Integer code;
    private String msg;
    private T data;

    public static <T> CommonsResp<T> failed(Integer code, String msg, T data) {
        return new CommonsResp(code,msg,data);
    }

    public static <T> CommonsResp<T> failed(Integer code, String msg) {
        return new CommonsResp(code,msg,null);
    }

    public static <T> CommonsResp<T> failed() {
        return new CommonsResp(RespEnum.FAILED.getCode(),RespEnum.FAILED.getMsg(),null);
    }

    public static <T> CommonsResp<T> failed(T data) {
        return new CommonsResp(RespEnum.FAILED.getCode(),RespEnum.FAILED.getMsg(),data);
    }

    public static <T> CommonsResp<T> succeess(Integer code, String msg, T data) {
        return new CommonsResp(code,msg,data);
    }

    public static <T> CommonsResp<T> succeess(Integer code, String msg) {
        return new CommonsResp(code,msg,null);
    }

    public static <T> CommonsResp<T> succeess() {
        return new CommonsResp(RespEnum.SUCCESS.getCode(),RespEnum.SUCCESS.getMsg(),null);
    }

    public static <T> CommonsResp<T> succeess(T data) {
        return new CommonsResp(RespEnum.SUCCESS.getCode(),RespEnum.SUCCESS.getMsg(),data);
    }

    private CommonsResp(){}

    private CommonsResp(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
